// 用 store.js操作
import LS from "store";
import { UPDATE_ALl_AUTHORITY_TYPE, CLEAR_ALl_AUTHORITY_TYPE } from "./types";
import { message } from "antd";
import { postLoginApi } from "@/api/auth";
// 把router引入使用路由实例 用history
import { router } from "@/utils/common";
const actions = {
    loginAction: (values) => async(dispatch) => {
        try {
            const data = await postLoginApi(values);
            dispatch({ type: UPDATE_ALl_AUTHORITY_TYPE, data });
            console.log("登录相关", data);
            LS.set("userinfo", data);
        } catch (error) {
            console.log("登录dispatch错误：", error);
        }
    },
    // logout
    logoutAction: () => {
        // 1清空缓存
        LS.remove("userinfo");

        // 3跳转到登录
        setTimeout(() => {
            router.history.push("/login");
        }, 0);
        // 2 清空store
        message.success("退出成功");
        return { type: CLEAR_ALl_AUTHORITY_TYPE };
    },
};
export default actions;